package logic

import (
	"context"
	"shopexam/shoprpc/shoprpc"

	"shopexam/api/internal/svc"
	"shopexam/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopAddLogic) ShopAdd(req *types.ShopAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.ShopRpc.ShopAdd(l.ctx, &shoprpc.ShopAddRequest{
		Nums:     req.Nums,
		Name:     req.Name,
		Price:    float32(req.Price),
		OldPrice: float32(req.OldPrice),
		Image:    req.Image,
		Intro:    req.Intro,
		UserId:   int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Msg:  "发布失败",
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "发布成功",
		Code: 200,
		Data: add,
	}, nil
}
